﻿@model Niunan.VideoSys.Model.Advertiesment
@{
    ViewBag.Title = Model.id == 0 ? "新增广告" : "编辑广告";
}
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li class="layui-this">@ViewBag.Title</li>
    </ul>
</div>
<form class="layui-form" action="">

    <div class='layui-form'>
        <div class='layui-form-item'>
            <label class='layui-form-label'>跳转连接</label>
            <div class='layui-input-inline'>
                @Html.TextBoxFor(a => a.link, new { @class = "layui-input", lay_verify = "required", placeholder = "http://" })
            </div>
            <div class='layui-form-mid layui-word-aux'><!--辅助文字--></div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>广告内容</label>
            <div class='layui-input-inline'>
                <input type="file" name="file" class="layui-upload-file">
                <span id="upload_result">@Model.path</span>
                @Html.HiddenFor(a => a.path)
                <div style="color:red;">只允许上传JPG,GIF,MP4,SWF类型的广告文件</div>
            </div>
            <div class='layui-form-mid layui-word-aux'><!--辅助文字--></div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>类型</label>
            <div class='layui-input-inline'>

                @{
                string[] ss = new string[] { "jpg", "gif", "swf", "mp4" };
                <select name="type">
                    @foreach (var item in ss)
                {
                    string str = "";
                    if (Model.type == item)
                    {
                        str = "selected='selected'";
                    }
                    <option value="@item" @str>@item</option>
            }
                </select>
                }
            </div>
            <div class='layui-form-mid layui-word-aux'><!--辅助文字--></div>
        </div>

        <div class='layui-form-item'>
            <label class='layui-form-label'>广告时长(秒)</label>
            <div class='layui-input-inline'>
                @Html.TextBoxFor(a => a.time, new { @class = "layui-input", lay_verify = "required" })
            </div>
            <div class='layui-form-mid layui-word-aux'><!--辅助文字--></div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>广告类型</label>
            <div class='layui-input-inline'>
                @{
                string[] ss2 = new string[] { "front,前置广告", "pause,暂停广告", "end,结束广告" };
                <select name="remark">
                    @foreach (var item in ss2)
                {
                    string v1 = item.Split(',')[0];
                    string v2 = item.Split(',')[1];
                    string str = "";
                    if (Model.remark == v1)
                    {
                        str = "selected='selected'";
                    }
                    <option value="@v1" @str>@v2</option>
            }
                </select>
                }
            </div>
            <div class='layui-form-mid layui-word-aux'><!--辅助文字--></div>
        </div>



        <div class="layui-form-item">
            <label class='layui-form-label'>&nbsp;</label>
            <div class="layui-input-inline">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">@ViewBag.Title</button>
                @Html.AntiForgeryToken()
                @Html.HiddenFor(a => a.id)
            </div>
        </div>
    </div>

</form>
 
<script>
var pop_index;

 

        /*加载layui编辑器*/
        layui.use(['form',  'layer','laydate','upload'], function () {
            var form = layui.form();
var laydate = layui.laydate;
var layer = layui.layer;
var $=layui.jquery;


layui.upload({
    url: '/Adnn1n/Home/ImgUpload' //上传接口
    , title: '上传文件'
      ,ext: 'jpg|gif|mp4|swf'
                , success: function (res) { //上传成功后的回调
                    // console.log(res);
                    document.getElementById("upload_result").innerHTML = res.data.src; 
                    document.getElementById("path").value = res.data.src; 
                }
            });



            //监听提交
            form.on('submit(demo1)', function (data) {
                var url = "/adnn1n/Advertiesment/add";
                var postdata = data.field;
				//postdata.body = editor1.html();
				pop_index = layer.load(0, {
                shade: [0.3, '#000'] //0.1透明度的白色背景
            });
                $.post(url, postdata, function (data) {
                layer.close(pop_index);
                    if (data.code == 0) {
                        layer.msg(data.msg, function () { location.href = "/adnn1n/Advertiesment/";})
                    } else {
                        layer.msg(data.msg);
                    }
                }, 'json')
                return false;
            });

        });
</script>
